package com.szyjjk.service;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.szyjjk.entity.RunMapData;
import com.szyjjk.mapper.RunMapDataMapper;

@Service
@Transactional(readOnly = true)
public class RunMapDataService {

	@Autowired
	private RunMapDataMapper runMapDataMapper;

	@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
	public void insertList(List<RunMapData> list, String tableName) {
		try {
			runMapDataMapper.insertList(list, tableName);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
	public void deleteByMapId(String id) {
		Map<String, String> map = new HashMap<>();
		map.put("mapId", id);

		for (int i = 1; i < 6; i++) {
			map.put("tableName", "run_map_data_" + i);
			try {
				runMapDataMapper.deleteByMapId(map);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	/**
	 * @Author yangyue
	 * @Description //TODO 查询数据		type =0 是查询数据  type =1 是查询最小值  type =2 是查询最大值
	 * @Date 17:01 2020/11/2
	 * @Param [proName, mapId, time, tableName]
	 * @return java.util.List<com.szyjjk.entity.RunMapData>
	 **/
	public List<RunMapData> findMapData(String proName,String mapId,Date time,String tableName ){
		 return 	runMapDataMapper.findMapDate(proName,mapId,time,tableName);
	}

	public List<RunMapData> findMapDateDistinct(String proName,String mapId,Date time,String tableName ){
		if(StringUtils.isBlank(mapId)) {
			return new ArrayList<RunMapData>();
		}
		 return 	runMapDataMapper.findMapDateDistinct(proName,mapId,time,tableName);
	}
	public List<RunMapData> findByMapId(String tableName, String MapId) {
		try {
			return runMapDataMapper.findByMapId( tableName,  MapId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	@Transactional(readOnly = false)
	public void updateById(String tableName, RunMapData run) {
		
		try {
			 runMapDataMapper.updateById(tableName, run.getId(),run.getMapSiteXy());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}


//	public List



}
